/**
  messages.h - Created by Timothy Morey on 5/13/2012
*/

#ifndef __MESSAGES_H
#define __MESSAGES_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "data-schema.h"
#include "layer.h"
#include "libnvn.h"

enum MESSAGETYPE
{
  MessageTypeUnknown,
  MessageTypeRequest,
  MessageTypeResponse
};

typedef enum MESSAGETYPE MessageType;

EXPORT int GetMessageInfo(const char* buf, int len, MessageType* type, char* name, int nameLen);

EXPORT int CreateAddLayerRequest(LayerProperties props, char* buf, int* len);
EXPORT int ParseAddLayerRequest(const char* buf, int len, LayerProperties* props);

EXPORT int CreateAdjustDisplayRequest(int x, int y, int width, int height, int borderless, 
                                        char* buf, int* len);
EXPORT int ParseAdjustDisplayRequest(const char* msg, int len, 
                                     int* x, int* y, int* width, int* height, int* borderless);

EXPORT int CreateCloseDisplayRequest(char* buf, int* len);

EXPORT int CreateQueryDataGridSchemaRequest(const char* dataset, const char* varname, 
                                            char* buf, int* len);
EXPORT int ParseQueryDataGridSchemaRequest(const char* msg, int len,
                                           char* dataset, int datasetlen,
                                           char* varname, int varnamelen);

EXPORT int CreateQueryDataGridSchemaResponse(DataGridSchema schema, char* buf, int* len);
EXPORT int ParseQueryDataGridSchemaResponse(const char* msg, int len, DataGridSchema* schema);

EXPORT int CreateQueryDataSetSchemaRequest(const char* dataset, char* buf, int* len);
EXPORT int ParseQueryDataSetSchemaRequest(const char* msg, int len,
                                          char* dataset, int datasetlen);

EXPORT int CreateQueryDataSetSchemaResponse(DataSetSchema schema, char* buf, int* len);
EXPORT int ParseQueryDataSetSchemaResponse(const char* msg, int len, DataSetSchema* schema);

EXPORT int CreateSimpleRequest(const char* name, const char* msg,
                               char* buf, int* len);
EXPORT int ParseSimpleRequest(const char* buf, int len, 
                              char* name, int namelen, char* msg, int msglen);

EXPORT int CreateSimpleResponse(int success, const char* name, const char* msg, 
                                char* buf, int* len);
EXPORT int ParseSimpleResponse(const char* buf, int len, 
                               int* success, char* name, int namelen, 
                               char* msg, int msglen);

EXPORT int CreateStartStreamRequest(int port, const char* dataset, const char* varname,
                                    char* buf, int* len);
EXPORT int ParseStartStreamRequest(const char* msg, int len, int* port,
                                   char* dataset, int datasetlen,
                                   char* varname, int varnamelen);

#ifdef __cplusplus
}
#endif

#endif
